document.addEventListener('plusready', function(){
    //注册工具类
var _BARCODE = 'Util',
B = window.plus.bridge;
var Util = {
    isServiceRunning: function(successCallback, errorCallback) {
        var success = typeof successCallback !== 'function' ? null : function(args) {
                successCallback(args);
            },
            fail = typeof errorCallback !== 'function' ? null : function(code) {
                errorCallback(code);
            };
        callbackID = B.callbackId(success, fail);
        return B.exec(_BARCODE, "isServiceRunning", [callbackID]);
    },
    // 声明异步返回方法
    PluginTestFunction : function (successCallback, errorCallback ) 
    {
        var success = typeof successCallback !== 'function' ? null : function(args) 
        {
            successCallback(args);
        },
        fail = typeof errorCallback !== 'function' ? null : function(code) 
        {
            errorCallback(code);
        };
        callbackID = B.callbackId(success, fail);
        // 通知Native层plugintest扩展插件运行”PluginTestFunction”方法
        return B.exec(_BARCODE, "PluginTestFunction", [callbackID]);
    }
};
window.plus.Util = Util;
//console.log("所有plus api都应该在此事件发生后调用，否则会出现plus is undefined。"
// 获取主Activity对象的实例
var main = plus.android.runtimeMainActivity();
//  导入android.content.Intent类对象
var Intent = plus.android.importClass("android.content.Intent");
// 导入后可以使用new方法创建类的实例对象,这里如果没启用权限，启用
/*main.startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));

var intent = new Intent();
intent.setClassName(main, "com.cnupai.mall.server.WeChatNotificationListenerService");
main.startService(intent);	
*/
/*plus.Util.PluginTestFunction(function( result ) {alert( result );},function(result){alert(result)});
//检测是否启动
plus.Util.isServiceRunning(
    function(result) {
        alert( "hehe");
    },function(result){
        alert(result)
    }
);*/

　　
/*var suppressLint = plus.android.importClass('android.annotation.SuppressLint');
var notification = plus.android.importClass('android.app.Notification');
var bundle = plus.android.importClass('android.os.Bundle');
var NotificationListenerService = plus.android.importClass('android.service.notification.NotificationListenerService');
var statusBarNotification = plus.android.importClass('android.service.notification.StatusBarNotification');   		


// 实现接口“NotificationMonitor ”对象
var hevent = plus.android.implements( "NotificationMonitor", {
    "onNotificationPosted":function( statusBarNotification ){
        console.log(1);
    }
} );
// 创建对象的实例
var notificationListenerService = new NotificationListenerService();
// 设置监听对象
notificationListenerService.setEventObserver( hevent );*/
/*console.log(statusBarNotification.getNotification().extras);
console.log(statusBarNotification.getPackageName());
console.log(Notification.EXTRA_TITLE);
console.log(Notification.EXTRA_TEXT);*/ 			
var context = plus.android.importClass("android.content.Context");//获取上下文
var receiver = plus.android.implements("io.dcloud.feature.internal.reflect.BroadcastReceiver",{

    onReceive:function(context,intent){

        plus.android.importClass(intent);
        //var msg = intent.getStringExtra("location.reportsucc");
        
        //alert(msg);
        console.log(intent.getExtra("notificationInfo"));
    }

});

var IntentFilter = plus.android.importClass('android.content.IntentFilter'); //引入过滤器
var Intent = plus.android.importClass('android.content.Intent');
var filter = new IntentFilter();
filter.addAction('location.reportsucc') //监听扫码广播
    //filter.addDataScheme("package");
main.registerReceiver(receiver, filter); //注册监听

//检测是否在运行



var ActivityManager = plus.android.importClass("android.app.ActivityManager");
plus.android.importClass("java.util.List");
function isServiceRunning(){
    var activityManager=main.getSystemService(context.ACTIVITY_SERVICE);

    if(plus.android.invoke('com.cnupai.mall.server.Util', 'isServiceRunning', activityManager, 'com.cnupai.mall.server.WeChatNotificationListenerService')){
        console.log('监听中');
    }else{
        console.log('未监听，重新绑定');
        main.startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
        var intent = new Intent();
        intent.setClassName(main, "com.cnupai.mall.server.WeChatNotificationListenerService");
        main.startService(intent);	

    }

};
setInterval(isServiceRunning, 3000);
});
